/**
 * @file Common.hh
 * @author Xiaoze Lin (linxiaoze96@gmail.com)
 * @brief Define common data types.
 * @version 0.1
 *
 * @copyright Copyright (c) 2024
 *
 */

namespace ifsim {

#define NUM_VALS 6  // 6 types of val, not include VAL_S

typedef enum
{
  VAL_ZERO,
  VAL_ONE,
  VAL_X,
  VAL_D,
  VAL_DBAR,
  VAL_Z
} GateValue;

typedef enum
{
  SA0,
  SA1
} FaultType;

typedef enum
{
  EQ,
  UU,
  TI,
  BL,
  RE,
  DT,
  DI_SCAN,
  DI_CLK,
  DI_SEN,
  DS,
  UO,
  UC,
  PT,
  AU,
  AU_SEQ,
  UNKNOWN,
  NP,
  ND
} FaultClass;

typedef enum
{
  T_JUNK,
  T_INPUT,
  T_OUTPUT,
  T_XOR,
  T_XNOR,
  T_DELAY_ELEMENT,  // Delay element: delay the value by one cycle
                    // which is referred as DFF in ISCAS89 format
  T_AND,
  T_NAND,
  T_OR,
  T_NOR,
  T_NOT,
  T_BUF,
  T_TIE1,
  T_TIE0,
  T_TIEX,
  T_TIEZ,
  T_MUX_2,        // 2-to-1 MUX
                  //   predecessors are (SEL, D0, D1)
  T_BUF_FB,       // feedback buffer; intentionly inserted for identified
                  //   combinational feedback loop
  T_BUS,          // BUS gate; do not adjust Z out
  T_BUS_GOHIGH,   // BUS gate; adjust Z out to 1 in the end
  T_BUS_GOLOW,    // BUS gate; adjust Z out to 0 in the end
  T_BUS_X,        // BUS gate; adjust Z out to X in the end
  T_BUFZ,         // initially take the id of BUSZ
                  // it is used after BUS to convert Z to X
  T_TRISTATEBUF,  // tristate buffer with active high enable
                  // predecessors are (EN, D)
  T_TRISTATEINV,  // tristate inverter with active high enable
                  // predecessors are (EN, D)
  T_DLA_PRI,      // active-high D latch primitive with set, reset
                  // predecessors are (SET, RESET, CLOCK, DATA)
  T_DFF_PRI,      // pos-edge D flip flop with set, reset
                  // predecessors are (SET, RESET, CLOCK, DATA)
  T_LAST_GTYPE
} GType;

typedef struct OclGate
{
  bool isScan;      // flag to indicate whether is in scan chain
  short gtype;      // gate type
  short level;      // level where the gate is at
  short numPreds;   // number of fanin  gates
  short numSuccs;   // number of fanout gates
  int offsetPreds;  // offset to base pointer of preds[]
  int offsetSuccs;  // offset to base pointer of succs[]
} OclGate;
}  // namespace ifsim